import Vue from 'vue'
import Vuex from 'vuex'

import state from "./components/state"
import mutations from "./components/mutation"
import actions from "./components/action"
import getters from "./components/getter"

Vue.use(Vuex)

const store = new Vuex.Store({
	state,
	actions,
	mutations,
	getters
})

// 监听聊天列表的值， 发生变化就保存在sessionStorage中
store.watch(
	(state) => state.chatList,
	(val) => {
		sessionStorage.setItem(state.user.id + 'chatlist', JSON.stringify(val));
	},
	{
		deep: true
	}
)

export default store